package com.neusoft.hifly.commons.exception;

import com.neusoft.hifly.core.log.Log;

/**
 * Title: 核心类库
 * <p>
 * Description: 系统异常
 * <p>
 * Copyright: 2019
 * <p>
 * Company: 东软汉枫
 *
 * @author lh_neu
 * @version 1.0.0
 */
public class SystemErrorException extends Exception { // 嵌套事务的回滚只对RuntimeException和Error有效
	private static final long serialVersionUID = 496560256169239352L;
	private int errorCode; // 异常代码
	private String errorDesc; // 异常描述

	/**
	 * 默认构造方法
	 */
	public SystemErrorException() {

	}

	/**
	 * 构造方法
	 *
	 * @param throwable
	 *            异常
	 */
	public SystemErrorException(final Throwable throwable) {
		this.errorDesc = throwable.getMessage();
		Log.error(errorDesc, throwable);
	}

	/**
	 * 异常编号和异常信息提交异常
	 *
	 * @param errorCode
	 *            异常编号
	 * @param errorDesc
	 *            异常信息
	 */
	public SystemErrorException(final int errorCode, final String errorDesc) {
		this.errorCode = errorCode;
		this.errorDesc = errorDesc;
		Log.error("系统异常。<{}> {}.", new Object[] { errorCode, errorDesc });
	}

	/**
	 * 异常信息提交异常
	 *
	 * @param errorDesc
	 *            异常信息
	 */
	public SystemErrorException(final String errorDesc) {
		this.errorDesc = errorDesc;
	}

	/**
	 * 异常信息提交异常
	 *
	 * @param errorDesc
	 *            异常信息
	 * @param throwable
	 *            异常
	 */
	public SystemErrorException(final String errorDesc, final Throwable throwable) {
		super(errorDesc, throwable);
		this.errorDesc = errorDesc;
	}

	public int getErrorCode() {
		return this.errorCode;
	}

	public void setErrorCode(final int errorCode) {
		this.errorCode = errorCode;
	}

	public String getErrorDesc() {
		return this.errorDesc;
	}

	public void setErrorDesc(final String errorDesc) {
		this.errorDesc = errorDesc;
	}
}
